package uk.me.dewi.appenin.android.entity;

import java.util.Date;
import java.util.HashMap;

import uk.me.dewi.validation.ValidationException;

public class Person {
    public Long mId;
    public String mName;
    public String mEmail;
    public Date mCreated;
    public Date mModified;
    
    public Person(){
        this.mCreated = new Date();
        this.mModified = mCreated;
    }
    
    public Person(String name, String email){
        this();
        this.mName = name;
        this.mEmail = email;
    }
    
    public String toString(){
        return "Person[id="+mId+", name="+mName+"]";
    }
    
    public Person validate() {
        HashMap<String, String> problems = new HashMap<String, String>();
        
        if(mName == null) problems.put("name", "null");
        else if(mName.trim().length() == 0) problems.put("name", "empty");
        
        if(mEmail == null) problems.put("description", "null");
        else if(mEmail.trim().length() == 0) problems.put("email", "empty");
        
        if(!problems.isEmpty()){
            throw new ValidationException("Invalid Place", problems);
        }
        
        return this;
    }
    
}
